<!-- 公司详情 -->
<template>
    <page-header-wrapper @back="() => $router.go(-1)">
        <a-card :bordered="false" title="基本信息">
            <a-descriptions >
                <a-descriptions-item label="公司名称" >{{company.companyName}}</a-descriptions-item>
                <a-descriptions-item label="统一社会信用代码" >{{company.socialCode}}</a-descriptions-item>
                <a-descriptions-item label="联系人" >{{company.contactName}}</a-descriptions-item>
                <a-descriptions-item label="联系电话" >{{company.contactPhone}}</a-descriptions-item>
                <a-descriptions-item label="服务费率" :span="3"><a href="javascript:void(0)">{{company.serviceRate ?? 0}}%</a><a style="margin-left: 20px" href="javascript:void(0)" @click="showBill">修改记录</a></a-descriptions-item>
            </a-descriptions>
            
        </a-card>
        <a-card style="margin-top:20px" :bordered="false">
            <a-tabs default-active-key="1">
                <a-tab-pane key="1" tab="关联账户">
                    <payAccount :customerBusinessId="company.customerBusinessId"/>
                </a-tab-pane>
                <a-tab-pane key="2" tab="合同管理" force-render>
                    <contracts :customerBusinessId="company.customerBusinessId"/>
                </a-tab-pane>
            </a-tabs>
        </a-card>

        <a-modal 
            v-model="visible" 
            title="修改记录"
            width="70%"
            @ok="visible = false" 
            @cancel="visible = false">
            <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange"  size="small" >
                <div slot="createTime" slot-scope="createTime,record">
                    <div>{{record.updateTime ?? createTime}}</div>
                </div>
                <div slot="beforeServiceRate" slot-scope="beforeServiceRate">
                    <div>{{beforeServiceRate}}%</div>
                </div>
                <div slot="afterServiceRate" slot-scope="afterServiceRate">
                    <div>{{afterServiceRate}}%</div>
                </div>
                <div slot="createdBy" slot-scope="createdBy,record">
                    <div>{{record.updatedBy ?? createdBy}}</div>
                </div>
            </a-table>
        </a-modal>
    </page-header-wrapper> 
</template>

<script>
import payAccount from './components/payAccount';
import contracts from './components/contracts';
import { getCompayDetail } from '@/api/services/company';
import { getCustomerBusinessRateRecord } from '@/api/services/customer';
import { columns } from './table';
export default {
    components: {
        payAccount,
        contracts,
    },
    data () {
        return {
            companyId: '',
            company: {},
            dataList: [],
            isload: false,
            page: 1,
            size: 10,
            visible: false,
            columns,
        };
    },
    created(){
        // this.companyId = this.$route.query.companyId;
        this.company = JSON.parse(this.$route.query.detail)
        console.log(this.company)
        // this.getDetail();
    },
    methods: {
        // 获取详情信息
        getDetail(){
            let _this = this;
            getCompayDetail(_this.companyId)
            .then(res => {
                if(res.success){
                    _this.company = JSON.parse(JSON.stringify(res.data));
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 查询修改记录
        showBill(){
            this.visible = true
            this.getData();
        },
        // 获取列表数据
        getData(){
            let _this = this
            _this.isload = true
            const params = {
                'pageIndex': _this.page,
                'pageSize': _this.size,
                'customerBusinessId': _this.company.customerBusinessId,
            }
            getCustomerBusinessRateRecord(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
    }
}

</script>
<style scoped>

</style>